{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python374jvsc74a57bd02a7e95a32014fc1ccf24626d45a98c6e7b4373277259c22f47a91d487fc3e8a5",
   "display_name": "Python 3.7.4 64-bit ('base': conda)"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 图像处理库\n",
    "# pillow\n",
    "# OpenCV\n",
    "# Skimage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 生物信息学库\n",
    "# Biopython"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 人文社科应用\n",
    "from nltk.corpus import inaugural\n",
    "fd3 = FreqDist([s for s in inaugural.words()])\n",
    "# print(fd3.freq('freedom'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 利用机器学习实现分类任务\n",
    "# 原网址 https://www.icourse163.org/learn/NJU-1001571005?tid=1463102441#/learn/content?type=detail&id=1240380202&cid=1261816441&replay=true\n",
    "import pandas as pd \n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.ensemble import RandomForestClassifier\n",
    "from sklearn.model_selection import GridSearchCV\n",
    "import warnings \n",
    "warnings.filterwarnings('ignore')\n",
    "\n",
    "try:\n",
    "    wine = pd.read_csv('winequality-red.csv',sep=';')\n",
    "except:\n",
    "    print('cannot find the file')\n",
    "\n",
    "wine = wine.drop_duplicates()\n",
    "\n",
    "wine['quality'].value_counts().plot(kind = 'pie',autopct ='%.2f')\n",
    "plt.show()\n",
    "\n",
    "plt.subplot(121)\n",
    "sns.barplot(x = 'quality',y = 'volatile acidity',data = wine)\n",
    "plt.subplot(122)\n",
    "sns.barplot(x = 'quality',y = 'alcohol',data = wine)\n",
    "plt.show()\n",
    "\n",
    "from sklearn.preprocessing import LabelEncoder\n",
    "bins = (2,4,6,8)  # 将数据划分成左开右闭区间\n",
    "group_names = ['low','medium','high']\n",
    "wine['quality_lb'] = pd.cut(wine['quality'],bins = bins, labels = group_names) # 数据分箱, 增加一个属性来对数据分类\n",
    "lb_quality = LabelEncoder()\n",
    "wine['label'] = lb_quality.fit_transform(wine['quality_lb'])\n",
    "print(wine.label.value_counts())    # 数据分箱的各类别数量\n"
   ]
  }
 ]
}